import Vue from 'vue';
import Router from 'vue-router';
import Home from './views/Home.vue';
import Login from './login/Login';
import AllInfo from './info/AllInfo';
import Details from './info/Detail';
import Anzhidian from './info/Anzhidian';
import CesiumView from './info/CesiumView'
// import AddSingleUserInfo from './info/AddSingleUserInfo'
// import SingleUserInfo from './info/SingleUserInfo';
import Test from './info/Test';


Vue.use(Router);

var router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      // redirect: '/home',
      redirect:'/allinfo',
      component: Home,
      children: [
        {
          path: '/allinfo',
          component: AllInfo
        },
        {
          path: '/details',
          component: Details
        },
        {
          path: '/anzhidian',
          component: Anzhidian
        },
        {
          path:"/cesiumview",
          component:CesiumView
        },
        // {
        //   path:'/adduserinfo',
        //   component:AddSingleUserInfo
        // },
        // {
        //   path: '/singleUserInfo',
        //   component: SingleUserInfo
        // },
        {
          path: '/test',
          component: Test
        },
        
      ]
    },
    {
      path: '/login',
      component: Login
    }
  ]
});
export default router;

router.beforeEach((to, from, next) => {
  // console.log(to);
  if (to.path === '/login') {
    return next();
  } else {
    // 获取本地是否有sessionStorage
    var token = window.sessionStorage.getItem('token');
    if (token) {
      return next();
    } else {
      return next('/login');
    }
  }
});
